package net.sgoliver.android;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.view.MotionEvent;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class MyPositionOverlay extends Overlay {
	
	GeoPoint geoPoint;

	public MyPositionOverlay(GeoPoint point) {
		super();
		this.geoPoint = point;
	}

	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow){
		
		Projection projection = mapView.getProjection();
		Point centro = new Point();
		projection.toPixels(geoPoint, centro);

		//Definimos el pincel de dibujo
		Paint p = new Paint();
		p.setColor(Color.BLUE);

		Bitmap bm = BitmapFactory.decodeResource(
				mapView.getResources(), 
				R.drawable.marcador_google_maps);
		canvas.drawBitmap(bm, centro.x - bm.getWidth(), 
				              centro.y - bm.getHeight(), p);
	}
	

	@Override
	public boolean onTouchEvent(MotionEvent event, MapView mapView) {
		
		if (event.getAction() == 1) {
			GeoPoint p = mapView.getProjection().fromPixels((int) event.getX(),
					(int) event.getY());

			geoPoint = p;
			
		}
		return false;
	}



}
